package com.android.sq.zouqi.login;

import android.os.Handler;
import android.os.Message;

import com.android.sq.zouqi.Constants;


public class HandlerThread extends Thread {
	public int anim_time = 2; 	// 2秒
	public boolean is_anim = true;
    public Handler handler;
    public Message msg;
    private boolean is_run = true;
    private long start_time;
    private long current_time;
    /**
     * 初始化构造函数
     * @param handler handler 用于发送消息
     * @param anim_time 动画周期
     */
    public HandlerThread(Handler handler, int anim_time) {
        super();
        this.handler = handler;
        this.anim_time = anim_time;
        start_time = System.currentTimeMillis();
    }
    @Override
    public void run() {
        while(is_run){
        	//Log.e("BA", "TIMER IS RUNNING");
            current_time = System.currentTimeMillis();
            if(current_time - start_time >= anim_time && is_anim) {
            	Message msg=new Message();
            	msg.what = Constants.ANIMATION_TIME_UP;
            	//Log.e("BA", "timerThread send time up message");
            	// 通知handler 此次动画的周期已到
            	handler.sendMessage(msg);
            	// 设置不能进行下一次动画周期
            	is_anim = false;
            } 
        }
        //super.run();
    }
    
    public void setTotal(int animation_time) {
    	this.anim_time = animation_time;
    }
    
    public void setIsRun(boolean is_run) {
    	this.is_run = is_run;
    }
    
    public void setStartTime(long start_time) {
    	this.start_time = start_time;
    }
    
    public void setIsAnim(boolean is_anim) {
    	this.is_anim = is_anim;
    }
}
